﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
using System.Configuration;
using System.IO;


namespace WcfCGServicesHost
{
    [RunInstaller(true)]
    public partial class CustomInstaller : System.Configuration.Install.Installer
    {
        #region Constructors 

        public CustomInstaller()
        {
            InitializeComponent();
        }

        #endregion

        #region Overrides

        public override void Install(IDictionary stateSaver)
        {
            base.Install(stateSaver);

            string targetDirectory = Context.Parameters["targetdir"];
            string tempFolder = Context.Parameters["TempFolder"];
            if (string.IsNullOrEmpty(tempFolder)
                || string.IsNullOrWhiteSpace(tempFolder))
                tempFolder = Path.GetTempPath();
            else
                if (!Directory.Exists(tempFolder))
                    Directory.CreateDirectory(tempFolder);

            string exePath = string.Format("{0}WcfCGServicesHost.exe", targetDirectory);
            Configuration config = ConfigurationManager.OpenExeConfiguration(exePath);
            config.AppSettings.Settings["TempFolder"].Value = tempFolder;

            config.Save();
        }

        #endregion
    }
}
